package com.yidu.action;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.common.Pages;
import com.yidu.common.Tools;
import com.yidu.domain.ListenBackstageUser;
import com.yidu.domain.ListenSell;
import com.yidu.domain.ListenSellDetail;
import com.yidu.service.ListenSellDetailService;
import com.yidu.service.ListenSellService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wujie
 * @since 2018-11-27
 */
@Controller
@RequestMapping("/listenSellDetail")
public class ListenSellDetailController {
	
	/**
	 * 注入service服务类
	 */
	@Resource
	private ListenSellDetailService listenSellDetailService;
	
	@RequestMapping("selectAll")
	@ResponseBody
	public Map<String, Object> selectAll(ListenSellDetail listenSellDetail,HttpSession session){
		ListenBackstageUser user = (ListenBackstageUser) session.getAttribute("user");
		Map<String, Object> map = new HashMap<>();
		if(!Tools.isEmpty(listenSellDetail.getSdId())) {
			map.put("sdId",listenSellDetail.getSdId());
		}
		
		if(!Tools.isEmpty(listenSellDetail.getSellId())) {
			map.put("sellId",listenSellDetail.getSellId());
		}else {
			map.put("sellId",listenSellDetail.getSellId());
		}
			map.put("companyId", user.getSite());
		
		if(listenSellDetail.getPage()!=null && listenSellDetail.getLimit()!=null) {
			Pages page=new Pages();
			page.setCurPage(listenSellDetail.getPage());
			page.setMaxResult(listenSellDetail.getLimit());
			
			map.put("firstRows", page.getFirstRows());
			map.put("maxResult", page.getMaxResult());
		}
		
		List<ListenSellDetail> list = listenSellDetailService.selectAll(map);
		int rows = listenSellDetailService.selectAllCount(map);
		
		
		Map<String, Object> layuiMap=new HashMap<>();
		
		layuiMap.put("code", 0);
		layuiMap.put("msg", "");
		layuiMap.put("count",rows);
		layuiMap.put("data", list);	
		return layuiMap;
	}
}

